home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0013_Making the Enter key work like a Tab.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  1.2 KB  |  29 lines

  1.  
  2. Code to make the <Enter>key act as the tab key while inside a grid.
  3.  
  4. This code also includes the processing of the <Enter> key for the entire
  5. application - including fields, etc.  The grid part is handled in the
  6. ELSE portion of the code.  The provided code does not mimic the behavior
  7. of the <Tab> key stepping down to the next record when it reaches the last 
  8. column in the grid - it moves back to the first column - .
  9.  
  10. procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
  11.  
  12. { This is the event handler for the FORM's OnKeyPress event! }
  13. { You should also set the Form's KeyPreview property to True }
  14. begin
  15.   if Key = #13 then                              { if it's an enter key }
  16.     if not (ActiveControl is TDBGrid) then begin { if not on a TDBGrid }
  17.       Key := #0;                                 { eat enter key }
  18.       Perform(WM_NEXTDLGCTL, 0, 0);              { move to next control }
  19.     end
  20.     else if (ActiveControl is TDBGrid) then      { if it is a TDBGrid }
  21.  
  22.       with TDBGrid(ActiveControl) do
  23.         if selectedindex < (fieldcount -1) then  { increment the field }
  24.           selectedindex := selectedindex +1
  25.         else
  26.           selectedindex := 0;
  27. end;
  28.  
  29.